# -*- coding: utf-8 -*-

'''
Created on 30 nov. 2009

@author: vincent.vanghelle
'''

from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect

from mmorganizer.games.models import Game
from django.contrib.auth.decorators import login_required

@login_required
def choosegame(request):
    gamelist = Game.objects.all()
    next = request.GET.get('next','')
    return render_to_response('games/selectgame.html',{'gamelist':gamelist,'next' :next, 'user':request.user})

@login_required
def selectgame(request,game_id):
    game = get_object_or_404(Game,id=game_id)
    profil = request.user.get_profile()
    profil.game = game
    profil.save()
    next = request.GET.get('next','')
    if next == '':
        HttpResponseRedirect('/index')
    return HttpResponseRedirect(next)

